package com.cdream.basic.algorithm.leetcode.tree;

/**
 * @author cdream
 * @date 6/6/21
 */
public class Question222 {
    public int countNodes(TreeNode root) {
        if (root == null) {
            return 0;
        }
        if (root.left == null && root.right == null) {
            return 1;
        }
        if (root.left == null || root.right == null) {
            return 2;
        }
        return countNodes(root.left) + countNodes(root.right) + 1;
    }
}
